package warmachineroster.grapheditor.figure;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.GridData;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.RectangleFigure;



public class UnitRosterElementFigure extends BaseRosterElementFigure {
	
	private BattleGroupFigure battleGroupFigure = new BattleGroupFigure();
	private Label unitSizeLabel;
	
	public UnitRosterElementFigure(String name, String armyListCode){
		super(name, armyListCode);
		add(battleGroupFigure);
	}

	@Override
	protected void configureFigurePanel() {
		addMainFigure(getFigurePanel());
		addNameLabel(getFigurePanel());
		addFieldAllowance(getFigurePanel());
		addPointCost(getFigurePanel());
		addAlFigureImg(getFigurePanel());
		addUnitSize(getFigurePanel());
		addSpecialRule(getFigurePanel());
	}
	@Override
	protected void addSpecialRule(Figure figure) {
		GridLayout layoutManager = (GridLayout) figure.getLayoutManager();
		RectangleFigure rect = new RectangleFigure();
		GridData gd = new GridData();
		gd.widthHint = 50;
		gd.horizontalSpan = 2;
		gd.grabExcessHorizontalSpace = true;
		layoutManager.setConstraint(rect, gd);
		figure.add(rect);
	}

	
	public BattleGroupFigure getBattleGroupFigure() {
		return battleGroupFigure;
	}

	protected void addUnitSize(Figure figure) {
		figure.add(new Label("Unit Size:"));
		if(unitSizeLabel == null)
			unitSizeLabel = new Label();
		figure.add(unitSizeLabel);
	}

	public void setUnitSize(int size) {
		getUnitSizeLabel().setText(String.valueOf(size));
	}
	
	protected Label getUnitSizeLabel() {
		return unitSizeLabel;
	}
}
